<template>
	<view class="page_scroll_view">
		<tn-navbar fixed :bottom-shadow="false">配送商详情</tn-navbar>
		<tn-sticky class="tn-white_bg">
			<view class="tn-flex items-center tn-p-sm">
				<tn-avatar :url="userInfo.delivery_image" size="xl" shape="square" />
				<view class="tn-ml-sm tn-flex tn-flex-1 tn-flex-column tn-text-xs" style="line-height: 1.7;">
					<text class="tn-mr-xs tn-text-ellipsis-1">配送名称：{{userInfo.delivery_name}}</text>
					<view class="tn-flex items-center">
						<text class="tn-mr">手机号码：{{userInfo.contact_tel}}</text>
						<tn-switch @change="changeActiveSwitch" v-model="userInfo.status" size="sm" :active-value="1"
							:inactive-value="0" active-text="正常" inactive-text="封禁" shape="square"
							active-color="tn-green" />
					</view>
					<text class="tn-text-ellipsis-1">注册地址：{{userInfo.address}}</text>
				</view>
			</view>
			<view class="gap" style="margin: 15rpx 0 10rpx;"></view>
			<tn-tabs v-model="currentTabIndex" :scroll="false">
				<tn-tabs-item v-for="(item, index) in tabsData" :key="index" :title="item.text" />
				<template #bar>
					<tn-icon name="tabs-smile" type="primary" />
				</template>
			</tn-tabs>
		</tn-sticky>
		<scroll-view scroll-y="true">
			<view class="tn-p tn-pb-sm">
				<UserInfoVue :userId="userInfo.id" v-if="currentTabIndex==0"></UserInfoVue>
				<ServiceRateVue :userId="userInfo.id" v-if="currentTabIndex==1"></ServiceRateVue>
				<PeriodicConfigVue :userId="userInfo.id" v-if="currentTabIndex==2"></PeriodicConfigVue>
			</view>
			<view style="height: 50rpx;"></view>
		</scroll-view>
	</view>
</template>

<script setup>
	import UserInfoVue from './components/UserInfo.vue';
	import ServiceRateVue from './components/ServiceRate.vue';
	import PeriodicConfigVue from './components/PeriodicConfig.vue';
	import {
		setUserStatusApi
	} from "@/request/worktop/index.js"
	import {
		ref
	} from 'vue';
	import {
		onLoad
	} from "@dcloudio/uni-app"
	import {
		base_url,
		domain_name,
		uploadHandle
	} from "@/request/index.js"

	onLoad((e) => {
		const user = JSON.parse(decodeURIComponent(e.item))
		userInfo.value = user
	})

	const userInfo = ref(null)
	const isLoading = ref(true)
	const currentTabIndex = ref(0)
	const tabsData = [{
			text: '详情资料',
		},
		{
			text: '服务费率',
		},
		{
			text: '周期配置',
		}
	]

	// 设置用户状态
	const changeActiveSwitch = (value) => {
		let obj = {
			id: userInfo.value.id,
			field: 'status',
			value
		}
		setUserStatusApi(obj).then(res => {
			if (res.code == 0) {
				uni.showToast({
					title: res.message,
				})
				userInfo.value.status = userInfo.value.status ? 1 : 0
			}
		}).catch(err => {
			uni.showToast({
				title: err.message,
				icon: 'none'
			})
		})
	}
</script>

<style scoped lang="scss">

</style>